import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:gluz/app/modules/auth/views/auth_base_view.dart';

import '../../../../common/common_button.dart';
import '../../../../common/form_components.dart';
import '../controllers/auth_gr_controller.dart';

class AuthGrView extends GetView<AuthGrController> with AuthBaseView {
  const AuthGrView({super.key});
  @override
  Widget build(BuildContext context) {
    return super.buildWidget();
  }

  // 表单内容
  @override
  Widget buildFormContent() {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 15),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(16),
        boxShadow: [
          BoxShadow(
            color: Colors.grey.withAlpha(50),
            blurRadius: 5,
            offset: const Offset(0, 4),
          ),
        ],
      ),
      child: Padding(
        padding: const EdgeInsets.all(20),
        child: GetBuilder<AuthGrController>(
            builder: (controller) {
              return Stack(
                children: [
                  Obx(() {
                    return Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        // 用户头像
                        Obx(
                              () =>
                              AvatarUploadField(
                                label: '用户头像'.tr,
                                imagePath: controller.avatarPath.value,
                                defaultAssets: 'assets/images/auth/auth_upload_image.png',
                                onTap: controller.uploadAvatar,
                              ),
                        ),

                        if (controller.selectedAuthType.value == '个人'.tr) ...[
                          FormInputField(
                            label: '用户名称'.tr,
                            isRequired: true,
                            controller: controller.userNickPhoneController,
                          ),
                          FormInputField(
                            label: '手机号'.tr,
                            readOnly: true,
                            isRequired: true,
                            keyboardType: TextInputType.number,
                            controller: controller.userPhoneController,
                          ),
                          FormInputField(
                            label: '姓名'.tr,
                            isRequired: true,
                            controller: controller.userNameController,
                          ),
                          // 企业名称
                          FormInputField(
                            label: '身份证号'.tr,
                            isRequired: true,
                            keyboardType: TextInputType.number,
                            controller: controller.userIdNumController,
                          ),
                          // 身份证照片
                          Obx(
                                () =>
                                DualImageUploadField(
                                  label: '身份证照片'.tr,
                                  frontImagePath: controller.idCardFrontPath
                                      .value,
                                  backImagePath: controller.idCardBackPath
                                      .value,
                                  onFrontTap: controller.uploadIdCardFront,
                                  onBackTap: controller.uploadIdCardBack,
                                ),
                          ),
                        ],
                      ],
                    );
                  }),
                  controller.getStatusWidget(),
                ],
              );
            }
        ),
      ),
    );
  }

  // 提交按钮
  @override
  Widget buildSubmitBtn() {
    // 提交按钮
    return SafeArea(
      child: Container(
        margin: EdgeInsets.symmetric(horizontal: 16, vertical: 16),
        child: GLGradientButton(
          onPressed: controller.submitForm,
          child: Text('确定'.tr, style: TextStyle(color: Colors.white)),
        ),
      ),
    );
  }
}
